#ifndef WINDOWMANAGER_H
#define WINDOWMANAGER_H

#pragma once
#include "listforms/chatlistform.h"

#include <QObject>
#include <QStackedWidget>
#include <QString>
#include <QWidget>
#include <map>

class WindowManager
    : public QObject {
    Q_OBJECT
public:
    WindowManager(QObject* parent = (QObject*)nullptr);
    ~WindowManager();

public:
    template <typename T>
    T* addSubWindow(QString windowName) {
        if (stackedWidget == nullptr) return nullptr;
        T* subWindow           = new T(stackedWidget);
        subWindows[windowName] = subWindow;
        stackedWidget->addWidget(subWindow);
        return subWindow;
    }
    void addSubWindow(QString windowName, QWidget* subWindow);
    void setCurrentWidget(QWidget *widget);

    void delSubWindow(QString windowName);
    void setStackedWidget(QStackedWidget* statckeWidget);
    ChatListForm *getChatListForm();
    void setChatListForm(ChatListForm * chatListForm);

signals:
    void signalAddSubWindow(QWidget* subWindows);

private:
    QStackedWidget*             stackedWidget;
    ChatListForm*               chatListForm = nullptr;
    std::map<QString, QWidget*> subWindows;
};

#endif